package sixthquestion;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        InputStream is = null;
        OutputStream os = null;
        try {
            serverSocket = new ServerSocket(8800);
            System.out.println("服务端开始等待客户端连接。。。");
            Socket socket =serverSocket.accept();
            System.out.println(socket.getInetAddress()+"客户端已连接");

            is = socket.getInputStream();
            os = new FileOutputStream(new File("F:/Java高级API/网络编程/src/main/网络编程作业/MyDoc/过年了.JPG"));
            byte[] bytes = new byte[1024];
            int temp=0;
            while ((temp=is.read(bytes))!=-1){
                os.write(bytes,0,temp);
                os.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (serverSocket!=null){
                try {
                    serverSocket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
